package com.sanbuTech.foundation.dao.common;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.executor.BatchResult;

import com.sanbuTech.util.DataPage;


public interface GenericDao {

    public long generateSequence(String sqlNameWithNameSpace);

    public <T> int insertAndReturnAffectedCount(String sqlNameWithNameSpace, T obj);

    public <T> int insertAndSetupId(String sqlNameWithNameSpace, T obj);

    public int update(String sqlNameWithNameSpace, Map<String, Object> param);

    public <T> int update(String sqlNameWithNameSpace, T obj);
    
	public int delete(String sqlNameWithNameSpace, Map<String, Object> param);
	
	public <T> int delete(String sqlNameWithNameSpace, T obj);
    
    public <T> T queryUnique(String statement, long id);

    public <T> T queryUnique(String statement, String idStr);

    public <T> T queryUnique(String sqlNameWithNameSpace, Map<String, Object> map);
    
    public <T> T queryUnique(String sqlNameWithNameSpace, Object obj);

    public int queryCount(String sqlNameWithNameSpace, Map<String, Object> map);
    
    /**
     * 因为 sun java编译器(javac)有个bug，会导致 "int result = 泛型返回值的queryOne()"有编译错误，而eclipse编译器是正确的。
     * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6302954
     * 所以增加这个没有泛型的queryInt()
     * 
     * @param sqlNameWithNameSpace
     * @param map
     * @return
     */
    public int queryInt(String sqlNameWithNameSpace, Map<String, Object> map);

    public <T> List<T> queryList(String sqlNameWithNameSpace, Map<String, Object> map, DataPage<T> page);

    public <T> DataPage<T> queryPage(String countSqlNameWithNameSpace, Map<String, Object> paramMap, 
			String rsSqlNameWithNameSpace, DataPage<T> page);

    public <T> List<T> queryList(String sqlNameWithNameSpace, Map<String, Object> map);
    
    /**
     * 采用mybatis.selectList获取第一个，判断超过exceptionExceedCount个就抛异常防止内存占用超出预期，fail-fast
     * @param sqlNameWithNameSpace
     * @param map
     * @param exceptionExceedCount
     * @return
     */
    public <T> List<T> queryList(String sqlNameWithNameSpace, Map<String, Object> map, int exceptionExceedCount);

    public <T> List<T> queryList(String sqlNameWithNameSpace);

    public <T> List<T> queryIdIn(String sqlNameWithNameSpace, long[] idList);

    public <T> List<T> queryIdIn(String sqlNameWithNameSpace, String[] idList);

    public <K, V> Map<K, V> selectOneToMap(String sqlNameWithNameSpace, Map<K, V> param);

    public List<BatchResult> flushStatements();
}
